package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.NewsAuthDto;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.dto.WmNewsVo;
import com.heima.media.entity.WmNews;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author gq
 * @since 2022-06-24
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
public class WmNewsController {

    @Autowired
    private IWmNewsService wmNewsService;

    /**
     * 文章列表分页查询
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.listByCondition(dto);
    }
    /**
     * 保存草稿\提交审核\更新
     *
     * @param dto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }
    /**
     * 根据ID查询文章
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getNewsById(@PathVariable ("id") Integer id){
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 文章上下架
     * @param dto
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult changeEnable(@RequestBody WmNewsDto dto){
        return wmNewsService.changeEnable(dto);
    }
    @PostMapping("findPageByName")
    public ResponseResult<List<WmNewsVo>> findPageByName(@RequestBody NewsAuthDto dto) {
        return wmNewsService.findPageByName(dto);
    }

    @GetMapping("findNewsVoById/{id}")
    public ResponseResult<WmNewsVo> findNewsVoById(@PathVariable("id") Integer id) {
        return wmNewsService.findNewsVoById(id);
    }

    @PostMapping("auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
        return wmNewsService.auth(dto, 1);
    }

    @PostMapping("auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
        return wmNewsService.auth(dto, 0);
    }
    @GetMapping("findNewsVoByid/{id}")
    public ResponseResult<WmNews> findNewsVoByid(@PathVariable("id") Integer id){
        return wmNewsService.findNewsVoByid(id);
    }
}
